Join Response.String() messages with a newline like .NET ConcatText - #742
Join Response.String() messages with a newline like .NET ConcatText#742PratikDhanave wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aligns agent.Response.String() output with the .NET ConcatText / AgentResponse.Text behavior by inserting a newline between each non-empty message’s text, instead of concatenating message texts with no separator.
Changes:
- Update
Response.String()to join each non-emptymsg.String()with\nand skip empty messages. - Add black-box tests covering newline joining, skipping empty messages without double newlines, and preserving within-message text concatenation across multiple
TextContentitems.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| agent/response.go | Changes Response.String() to newline-separate non-empty message text using msg.String() (which delegates to message.Contents.Text()). |
| agent/response_test.go | Adds TestResponse_String to validate cross-message newline joining and empty-message skipping while keeping within-message concatenation unchanged. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
Response.String() flattened every message's text into one builder with no separator, so a multi-message assistant turn returned "fooBar" where .NET AgentResponse.Text (backed by ChatMessage list ConcatText) returns "foo\nBar". Join each non-empty per-message text with a newline, skipping empty messages, matching .NET semantics. This also aligns the agent-as-tool result returned by agenttool's FuncTool, which surfaces resp.String().
a3831db to
f533990
Compare
This comment has been minimized.
This comment has been minimized.
# Conflicts: # agent/response_test.go
Head branch was pushed to by a user without write access
Go API Consistency Review — Parity Approved ✅PR: Join SummaryThis PR fixes a behavioral divergence in the exported Upstream reference verified:
Labels:
No parity issues identified. The PR improves cross-SDK consistency.
|
What
Response.String()flattened the text of every message into a singlestrings.Builderwith no separator. For a two-message assistant turn (foo,Bar) it returnedfooBar. It now joins each non-empty per-message text with a newline, yieldingfoo\nBar, and skips empty messages so no double newline is produced. Text glued within a single message (multipleTextContentitems) is unchanged.Why (.NET parity)
In microsoft/agent-framework,
AgentResponse.Textis backed bymessages.ConcatText().ConcatText(IList<ChatMessage>)documents that "A newline separator is added between each non-empty piece of text" and usesAppendLinebetween non-empty messages. The Go port glued messages together instead, so the same two-message turn producedfooBarin Go vsfoo\nBarin .NET.The per-message join was already correct:
msg.String()==message.Contents.Text(), the analog ofChatMessage.Text. This change reusesmsg.String()and only fixes the cross-message separator.This also aligns the agent-as-tool result: agenttool's
FuncToolreturnsresp.String()as the tool output, the analog of .NETAsAIFunctionreturningresponse.Text.Testing
Added
TestResponse_Stringinagent/response_test.go(black-box,package agent_test) covering: two single-text messages join with a newline; an empty middle message is skipped without a double newline; multipleTextContentitems within one message stay glued.go build ./...,go vet ./agent/..., andgo test ./agent/...(plus./tool/agenttool/...) pass.